// var mTeacherEvaltionPie = echarts.init(document.getElementById('teacherEvaltionPie'),'walden');
// var mTeacherEvaltionBar = echarts.init(document.getElementById('teacherEvaltionBar'),'walden');
var mTeacherAttendanceTimePie = echarts.init(document.getElementById('teacherAttendanceTimePie'),'walden');
// var mTeacherEvaltionRateBar = echarts.init(document.getElementById('teacherEvaltionRateBar'),'walden');
 var mTeacherEvaltionPieRate = echarts.init(document.getElementById('teacherEvaltionPieRate'),'walden');
// var mTeacherAttendanceTimePie = echarts.init(document.getElementById('teacherEvaltionRateBar'),'walden');

var mTeacherAttendancePie = echarts.init(document.getElementById('teacherAttendancePie'),'walden');
var mTeacherEvaltionTimeLine = echarts.init(document.getElementById('teacherEvaltionTimeLine'),'walden');

var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "menuId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var ztree;
// var teacherEvaltionPie  = {
//     title : {
//         text: '优良差占比',
//         x:'center'
//     },
//     tooltip : {
//         trigger: 'item',
//         formatter: "{a} <br/>{b} : {c} ({d}%)"
//     },
//     legend: {
//         orient: 'vertical',
//         left: 'left',
//         data: ['优','良','差']
//     },
//     series : [
//         {
//             name: '占比',
//             type: 'pie',
//             // radius : '55%',
//             // center: ['50%', '60%'],
//             data:[
//                 {value:335, name:'优'},
//                 {value:310, name:'良'},
//                 {value:234, name:'差'}
//             ],
//             itemStyle: {
//                 emphasis: {
//                     shadowBlur: 10,
//                     shadowOffsetX: 0,
//                     shadowColor: 'rgba(0, 0, 0, 0.5)'
//                 }
//             }
//         }
//     ]
// };
// var teacherEvaltionBar = {
//     tooltip : {
//         trigger: 'axis',
//         axisPointer : {            // 坐标轴指示器，坐标轴触发有效
//             type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
//         }
//     },
//     legend: {
//         data: ['优','良','差']
//     },
//     grid: {
//         left: '3%',
//         right: '4%',
//         bottom: '3%',
//         containLabel: true
//     },
//     yAxis : [
//         {
//             type : 'category',
//             data: ['教学态度','教学效果','教学内容','教学环节'],
//         }
//     ],
//     xAxis : [
//         {
//             type : 'value'
//         }
//     ],
//     series : [
//         {
//             name:'优',
//             type:'bar',
//             data:[2.0, 4.9, 7.0, 23.2]
//         },
//         {
//             name:'良',
//             type:'bar',
//             data:[2.6, 5.9, 9.0, 26.4]
//         },
//         {
//             name:'差',
//             type:'bar',
//             data:[2.0, 2.2, 3.3, 4.5]
//         }
//     ]
// };
var teacherEvaltionPieRate  = {
    title : {
        text: '教学进度相符率',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['相符','不相符']
    },
    series : [
        {
            name: '占比',
            type: 'pie',
            // radius : '55%',
            // center: ['50%', '60%'],
            data:[
                {value:335, name:'优'},
                {value:310, name:'良'},
                {value:234, name:'差'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
// var teacherEvaltionRateBar = {
//     tooltip : {
//         trigger: 'axis',
//         axisPointer : {            // 坐标轴指示器，坐标轴触发有效
//             type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
//         }
//     },
//     legend: {
//         data: ['相符','不相符']
//     },
//     grid: {
//         left: '3%',
//         right: '4%',
//         bottom: '3%',
//         containLabel: true
//     },
//     xAxis : [
//         {
//             type : 'category',
//             data: ['语文','数学','英语','体育'],
//         }
//     ],
//     yAxis : [
//         {
//             type : 'value'
//         }
//     ],
//     series : [
//         {
//             name:'相符',
//             type:'bar',
//             stack: '相符率',
//             barWidth:30,
//             data:[2.0, 4.9, 7.0, 23.2]
//         },
//         {
//             name:'不相符',
//             type:'bar',
//             stack: '相符率',
//             barWidth:30,
//             data:[2.6, 5.9, 9.0, 26.4]
//         }
//     ]
// };
var teacherAttendancePie  = {
    title : {
        text: '出勤情况',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['正常','迟到','早退','调整']
    },
    series : [
        {
            name: '占比',
            type: 'pie',
            // radius : '55%',
            // center: ['50%', '60%'],
            data:[
                {value:335, name:'正常'},
                {value:335, name:'迟到'},
                {value:310, name:'早退'},
                {value:234, name:'调整'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
var teacherEvaltionTimeLine = {
    title : {
        text: '授课时长纵向比',
        x:'center'
    },
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} 分钟'
        }
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true
    }]
};
var teacherAttendanceTimePie = {
    title: {
        text: '出勤率纵向比'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data:['正常','迟到','早退','调整']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['周一','周二','周三','周四','周五','周六','周日']
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            show: true,
            interval: 'auto',
            formatter: '{value} %'
        },
    },
    series: [
        {
            name:'正常',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[120, 132, 101, 134, 90, 230, 210]
        },
        {
            name:'迟到',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[220, 182, 191, 234, 290, 330, 310]
        },
        {
            name:'早退',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[150, 232, 201, 154, 190, 330, 410]
        },
        {
            name:'调整',
            type:'line',
            stack: '总量',
            smooth: true,
            data:[320, 332, 301, 334, 390, 330, 320]
        }
    ]
};

$(function () {
    vm.getTeacher();
  //  myChart.setOption(teacherEvaltionPie);
    }
);

function genData(count) {
    var nameList = [
        '赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常', '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵', '湛', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁', '杜', '阮', '蓝', '闵', '席', '季', '麻', '强', '贾', '路', '娄', '危'
    ];
    var legendData = [];
    var seriesData = [];
    var selected = {};
    for (var i = 0; i < 50; i++) {
        name = Math.random() > 0.65
            ? makeWord(4, 1) + '·' + makeWord(3, 0)
            : makeWord(2, 1);
        legendData.push(name);
        seriesData.push({
            name: name,
            value: Math.round(Math.random() * 100000)
        });
        selected[name] = i < 6;
    }

    return {
        legendData: legendData,
        seriesData: seriesData,
        selected: selected
    };

    function makeWord(max, min) {
        var nameLen = Math.ceil(Math.random() * max + min);
        var name = [];
        for (var i = 0; i < nameLen; i++) {
            name.push(nameList[Math.round(Math.random() * nameList.length - 1)]);
        }
        return name.join('');
    }
}

function setDate(id) {
    var Nowdate=new Date();
    M=Number(Nowdate.getMonth())+1;
    var today=Nowdate.getFullYear()+"-"+fix(M)+"-"+fix(Nowdate.getDate());
    if(id=='1'){
        $("#startDate").val(today);
        $("#endDate").val(today);
    }else if(id=='2'){
        $("#startDate").val(showWeekFirstDay());
        $("#endDate").val(today);
    }if(id=='3'){
        $("#startDate").val(showMonthFirstDay());
        $("#endDate").val(today);
    }
    query()
}
function showWeekFirstDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    M=Number(WeekFirstDay.getMonth())+1
    return WeekFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(WeekFirstDay.getDate());
}
function showWeekLastDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
    M=Number(WeekLastDay.getMonth())+1
    return WeekLastDay.getFullYear()+"-"+M+"-"+WeekLastDay.getDate();
}
function showMonthFirstDay()
{
    var Nowdate=new Date();
    var MonthFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth(),1);
    M=Number(MonthFirstDay.getMonth())+1
    return MonthFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(MonthFirstDay.getDate());
}
function fix(num){
    if(num<10)
        return "0"+num;
    else return ""+num;
}
function showMonthLastDay()
{
    var Nowdate=new Date();
    var MonthNextFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth()+1,1);
    var MonthLastDay=new Date(MonthNextFirstDay-86400000);
    M=Number(MonthLastDay.getMonth())+1
    return MonthLastDay.getFullYear()+"-"+M+"-"+MonthLastDay.getDate();
}
var vm = new Vue({
    el:'#rrapp',
    data:{
        collageData:null,
        yearData:null,
        termData:null,
        weekData:null,
        dayData:null,
        indexData:null,
        collageValue:[],
        yearValue:[],
        termValue:[],
        weekValue:[],
        dayValue:[],
        indexValue:[],
        collageOptions:[],
        yearOptions:[],
        termOptions:[],
        weekOptions:[],
        dayOptions:[],
        indexOptions:[],
        showList: true,
        title: null,
        teacher:{
            id:null,
            name:null
        },
        menu:{
            parentName:null,
            parentId:0,
            type:1,
            orderNum:0
        }
    },
    mounted(){
         $.ajax({
            url: baseURL + "/college/getAllcollege",
            data: {},
            success: function (r) {
                for (i = 0; i < r.list.length; i++) {
                    var tempJson={
                        'value':r.list[i].collegeName,
                        'label':r.list[i].collegeName
                    }
                    vm.collageOptions.push(tempJson)
                }
            }
        });
        $.ajax({
            url: baseURL + "/term/getSchoolTerm",
            data: {},
            success: function (r) {
                for (i = 0; i < r.list.length; i++) {
                     var tempJson={
                        'value':r.list[i].schoolAcademicYear,
                        'label':r.list[i].schoolAcademicYear
                    }
                    vm.yearOptions.push(tempJson)
                }
            }
         });
         var listTerm=["1","2"];
         for (i = 0; i < listTerm.length; i++) {
            var tempJson={
                'value':listTerm[i],
                'label':"第"+listTerm[i]+"学期"
            }
            this.termOptions.push(tempJson)
         }
         for (i = 1; i < 21; i++) {
            var tempJson={
                'value':i,
                'label':"第"+i+"周"
            }
            this.weekOptions.push(tempJson)
         }
         for (i = 1; i < 8; i++) {
           var tempJson={
                'value':i,
                'label':"星期"+i
            }
            this.dayOptions.push(tempJson)
         }
         for (i = 1; i < 11; i+=2) {
            var tempJson={
                'value':i,
                'label':"第"+i+"节"
            }
            this.indexOptions.push(tempJson)
         }
    },

    methods: {
        goString:function(data){
            var temp=""
            for(let i in data){
                if(i==data.length-1){
                    temp+=('\''+data[i]+'\'')
                }else{
                    temp+=('\''+data[i]+'\'')+','
                }
            }
            return temp
        },
        query:function () {
            vm.collageData=vm.goString(vm.collageValue);
            vm.yearData=vm.goString(vm.yearValue);
            vm.termData=vm.goString(vm.termValue);
            vm.weekData=vm.goString(vm.weekValue);
            vm.dayData=vm.goString(vm.dayValue);
            vm.indexData=vm.goString(vm.indexValue);
            $.ajax({
                url: baseURL + "TeacherPortrait/getTeacherEvaltionEcharts",
                data: {
                    "academicYear":vm.yearData,
                    "academicTerm":vm.termData,
                    "academicWeek":vm.weekData,
                    "academicDay":vm.dayData,
                    "academicIndex":vm.indexData,
                    "teacherId":vm.teacher.id,
                    "startDate":$("#startDate").val(),
                    "endDate":$("#endDate").val()
                },
                success: function (r) {
                    // teacherEvaltionPie.series[0].data=r.dataPie;
                    // teacherEvaltionBar.series=r.dataBar;
                    teacherEvaltionPieRate.series[0].data=r.dataRate;
                    teacherEvaltionTimeLine.xAxis.data=r.timeLine.xData;
                    teacherEvaltionTimeLine.series[0].data=r.timeLine.seriesData;
                    teacherAttendancePie.series[0].data=r.teacherAttendancePie;
                    teacherAttendanceTimePie.series=r.teacherAttendanceTimePie.data;
                    teacherAttendanceTimePie.xAxis= {
                        type: 'category',
                        data:r.teacherAttendanceTimePie.xAxis
                    };
                    // mTeacherEvaltionPie.setOption(teacherEvaltionPie);
                    // mTeacherEvaltionBar.setOption(teacherEvaltionBar);
                    mTeacherAttendanceTimePie.setOption(teacherAttendanceTimePie);
                    mTeacherEvaltionPieRate.setOption(teacherEvaltionPieRate);
                    // mTeacherEvaltionRateBar.setOption(teacherEvaltionRateBar);
                    mTeacherAttendancePie.setOption(teacherAttendancePie);
                    mTeacherEvaltionTimeLine.setOption(teacherEvaltionTimeLine);
                }
            });
        },
        getTeacher: function(){
            //加载菜单树
            $.get(baseURL + "TeacherPortrait/getTeacherTree", function(r){
                ztree = $.fn.zTree.init($("#teacherTree"), setting, r.list);
                var node = ztree.getNodeByParam("menuId", vm.menu.parentId);
                ztree.selectNode(node);
            })
            vm.imgUrl='';
        },
        teacherTree: function(){
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择专业",
                area: ['300px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#menuLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var node = ztree.getSelectedNodes();
                    //选择上级菜单
                    vm.teacher.id = node[0].menuId;
                    vm.teacher.name = node[0].name;

                    layer.close(index);
                }
            });
        }
}
});